<template>
  <div v-if="block">
    <slot></slot>
    <div v-if="$slots.footer"
         class="el-dialog__footer">
      <slot name="footer"></slot>
    </div>
  </div>
  <el-dialog
      v-else
      width="100vw"
      v-bind="$attrs"
      v-model="showDialog"
      draggable
      :title="title"
      append-to-body
      @closed="_closed"
  >
    <div class="dialogContent" :style="dialogContentStyle">
      <slot></slot>
    </div>
    <template #footer v-if="$slots.footer">
      <slot name="footer"></slot>
    </template>
  </el-dialog>
</template>

<script lang="ts">
import {CSSProperties, PropType} from "vue";

export default {
  name: 'DialogAndBlock',
  props: {
    block: {
      type: Boolean,
      default: false,
    },
    title: {
      type: String,
      default: '',
    },
    top: {
      type: String,
      default: '10vh',
    },
    contentOverflow: {
      type: String as PropType<CSSProperties["overflow"]>,
      default: () => 'auto'
    }
  },
  emits: ['closed'],
  data() {
    return{
      showDialog: false,
    }
  },
  computed: {
    dialogContentStyle() {
      return {
        overflow: this.contentOverflow
      }
    }
  },
  methods: {
    _closed() {
      this.$emit('closed')
    },
    open() {
      this.showDialog=true
    },
    close() {
      this.showDialog=false
    }
  }
}
</script>

<style lang="scss" scoped>
.dialogContent{
  max-height: 70vh;
}
.el-dialog__footer{
  padding-top: 16px;
}
</style>
